import { deletes } from '@/utils/axios'
export default {
  data() {
    return {
      dialog1: false,
      title: '修改',
      formId: '',
      searchForm: {}
    }
  },
  created() {
    // 调用表格加载
    this.handleFreshTable()
  },
  mounted() {
    this.handleAfterGetDict()
  },
  methods: {
    delSuccessNotify() {
      this.$notify({
        title: '删除成功',
        type: 'success',
        duration: 2500
      })
    },
    handleAfterGetDict() {},
    // 关闭弹窗
    handleCanleDialog() {
      const infoForm = this.$refs['infoForm']
      if (infoForm) {
        // 清除校验 清空表单
        const refformValid = infoForm.$refs['formValid']
        refformValid && refformValid.clearValidate()
        infoForm.clearForm()
      }
      this.dialog1 = false
      this.handleFreshTable()
    },
    // 窗口弹出
    handleOpenDialog(formId = '') {
      if (!this.openDialogConditions(formId)) {
        // 状态标识
        this.formId = formId
        this.dialog1 = true
        this.title = `${this.mainTitle}-${formId ? '编辑' : '添加'}`
      }
    },
    // 刷新表格
    handleFreshTable(page = undefined, limit = undefined) {
      this.$nextTick(() => {
        const dataTable = this.$refs.dataTable
        if (dataTable) {
          dataTable.dataFresh(page, limit, this.searchForm)
        }
      })
    },
    // 条件过滤
    handleSearchByKeyword(form) {
      this.searchForm = form
      this.handleFreshTable(1, 10)
    },
    handleDelRow(formId) {
      deletes(`${this.delUrl}`, { formId }).then((res) => {
        if (res.obj) {
          this.delSuccessNotify()
          this.handleFreshTable()
        }
      })
    },
    // 窗口弹出条件 接收打开参数
    openDialogConditions() {}
  }
}
